<template>
  <div class="tabBarItem" @click="toggle">
    <div v-if="!isActive">
      <slot name="item_icon"></slot>
    </div>
    <div v-else>
      <slot name="item_icon-active"></slot>
    </div>
    <div :class="{ active: isActive }">
      <slot name="item_text"></slot>
    </div>
  </div>
</template>

<script>
export default {
  name: 'TabBarItem',
  props: {
    link: String
  },
  computed: {
    isActive () {
      return this.$route.path.includes(this.link)
    }
  },
  methods: {
    toggle () {
      this.$router.replace(this.link)
    }
  }
}
</script>

<style lang="scss" scoped>
.tabBarItem {
  flex: 1;
  text-align: center;
  font-size: 12px;

  img {
    width: 24px;
    height: 24px;
    margin-top: 3px;
    vertical-align: middle;
    margin-bottom: 2px;
  }

  .active {
    color: #ff5777;
  }
}
</style>
